package com.bluesky.page;

import com.github.pagehelper.Page;
import lombok.Data;

import java.util.List;

@Data
public class PageResult<T> {

    /**
     * 页码
     */
    private int pageNum;

    /**
     * 每页的数量
     */
    private int pageSize;

    /**
     * 总记录数
     */
    private long total;

    private List<T> list;

    public static <T> PageResult<T> of(List<T> list){
        PageResult<T> result = new PageResult<>();
        result.list = list;
        if (list instanceof PageResult){
            Page<?> pg = (Page<?>)list;
            result.total = pg.getTotal();
            result.setPageNum(pg.getPageNum());
            result.setPageSize(pg.getPageSize());
        }else{
            result.total=list.size();
        }
        return result;
    }
}
